// +build !windows
package system

import (
	"syscall"
)

func SetLimit(limitSetting uint64, force bool ){
	var limit syscall.Rlimit

	syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit)

	//如果强制设置，不管系统原来的值
	if force {
		limit.Cur = limitSetting
	}else {
		// 如果系统值比设置高，则使用系统值
		if limit.Cur < limitSetting{
			limit.Cur = limitSetting
			if limit.Max < limitSetting{
				limit.Max = limitSetting
			}
		}
	}
	syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit)
}

func GetLimit() (uint64, uint64) {
	var limit syscall.Rlimit
	syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit)
	return  limit.Max, limit.Cur
}